<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%project_smi}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%project}}`
 */
class m230616_065644_create_project_smi_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%project_smi}}', [
            'id' => $this->primaryKey(),
            'title' => $this->string(512)->notNull(),
            'url' => $this->string(1024),
            'date_published' => $this->date(),
            'id_project' => $this->integer(),
        ]);

        // creates index for column `id_project`
        $this->createIndex(
            '{{%idx-project_smi-id_project}}',
            '{{%project_smi}}',
            'id_project'
        );

        // add foreign key for table `{{%project}}`
        $this->addForeignKey(
            '{{%fk-project_smi-id_project}}',
            '{{%project_smi}}',
            'id_project',
            '{{%project}}',
            'id',
            'SET NULL'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%project}}`
        $this->dropForeignKey(
            '{{%fk-project_smi-id_project}}',
            '{{%project_smi}}'
        );

        // drops index for column `id_project`
        $this->dropIndex(
            '{{%idx-project_smi-id_project}}',
            '{{%project_smi}}'
        );

        $this->dropTable('{{%project_smi}}');
    }
}
